package com.initialize.core.feign;

import com.initialize.commom.config.header.HeaderConfig;
import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;

import java.util.UUID;



/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2019/12/30
 * Time: 11:36 上午
 * Description: 给Fei给你添加请求头
 * 用于内部通信
 */
@Slf4j
@Configuration
public class FeignConfiguration {

    final
    Jedis jedis;

    public FeignConfiguration(Jedis jedis) {
        this.jedis = jedis;
    }

    @Bean
    public RequestInterceptor requestInterceptor() {

        return template -> {
            String uuidNo_ = UUID.randomUUID().toString().replace("-", "");
            jedis.sadd(HeaderConfig.INTERNAL_SECRET_KEY, uuidNo_);
            template.header(HeaderConfig.INTERNAL_SECRET_KEY, uuidNo_);

        };
    }
}